﻿<Window x:Class="Library.Windows.Clients"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Library.Windows"
        xmlns:classes="clr-namespace:Library.Classes"
        mc:Ignorable="d"
        Title="Читатели" Height="650" Width="800"
        WindowStartupLocation="CenterScreen"
        MinHeight="650" MinWidth="800">
    <Window.Resources>
        <!--<classes:DateTimeToDateConverter x:Key="DateConverter"/>-->
        <classes:BooleanToDataConverter x:Key="StatusConverter"/>
    </Window.Resources>

    <Grid x:Name="gridClientDetail">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="250"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <GroupBox Header="Добавление нового читателя"
                  x:Name="GroupHeader"
                  Margin="5">
            <StackPanel>
                <Label Content="Фамилия"/>
                <TextBox x:Name="lastName"/>

                <Label Content="Имя"/>
                <TextBox x:Name="firstName"/>

                <Label Content="Дата рождения"/>
                <DatePicker x:Name="birthday"/>

                <Label Content="Номер телефона"/>
                <TextBox x:Name="phoneNumber"/>

                <Label Content="Email"/>
                <TextBox x:Name="clientEmail"/>

                <Button Content="Добавить читателя"
                        Width="150" HorizontalAlignment="Right"
                        Margin="10 10"
                        x:Name="addClient"
                        Click="addClient_Click"/>
            </StackPanel>
        </GroupBox>
        <Grid Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition Height="30"/>
                <RowDefinition Height="260"/>
            </Grid.RowDefinitions>
            <GroupBox Header="Список клиентов"
                Margin="5" >
                <ListBox x:Name="listClients"
                         Margin="5"
                         SelectionChanged="listClients_SelectionChanged"
                         ItemsSource="{Binding}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid >
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="300"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Path=LastName}"
                                                Margin="5 0"/>
                                    <TextBlock Text="{Binding Path=FirstName}"/>
                                </StackPanel>
                                <TextBlock Text="{Binding StringFormat=Статус: {0},
                                    Converter={StaticResource StatusConverter}, Path=Status}"
                                           Grid.Column="1" x:Name="ClientStatus"/>
                            </Grid>
                            <DataTemplate.Triggers>
                                <DataTrigger Binding="{Binding Path=Status}" Value="true">
                                    <Setter TargetName="ClientStatus" Property="Foreground" Value="DarkGreen"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding Path=Status}" Value="false">
                                    <Setter TargetName="ClientStatus" Property="Foreground" Value="Red"/>
                                </DataTrigger>

                            </DataTemplate.Triggers>
                        </DataTemplate>
                    </ListBox.ItemTemplate>

                    <ListBox.ContextMenu>
                        <ContextMenu>
                            <MenuItem Header="Изменить"
                                      x:Name="ChangeRow"
                                      Click="ChangeRow_Click"/>
                            <MenuItem x:Name="DeleteClient"
                                      Click="DeleteClient_Click"/>

                        </ContextMenu>
                    </ListBox.ContextMenu>

                </ListBox>
            </GroupBox>
            <TextBlock Text="{Binding StringFormat=Количество строк {0}, 
                ElementName=listClients, Path=Items.Count}"
                       Grid.Row="1"/>
            <GroupBox Header="Информация о читателе"
                      Grid.Row="2">
                <StackPanel>
                    <Label Content="Фамилия"/>
                    <TextBlock x:Name="infoLastName"
                            Style="{StaticResource ResourceKey=info}"/>

                    <Label Content="Имя"/>
                    <TextBlock x:Name="infoFirstName"
                            Style="{StaticResource ResourceKey=info}"/>

                    <Label Content="Дата рождения"/>
                    <TextBlock x:Name="infoBirthday"
                            Style="{StaticResource ResourceKey=info}"/>

                    <Label Content="Номер телефона"/>
                    <TextBlock x:Name="infoPhone"
                            Style="{StaticResource ResourceKey=info}"/>

                    <Label Content="Email"/>
                    <TextBlock x:Name="infoEmail"
                            Style="{StaticResource ResourceKey=info}"/>
                </StackPanel>
            </GroupBox>
        </Grid>
    </Grid>
</Window>
